package com.itany.corejava.code09_异常;

/**
 * @author MissChen
 * @date 2024年03月07日 13:26
 */
public class Test04_自定义异常 {
    public static void main(String[] args) {
        try {
            register("admin","123456");
        } catch (UserExistException e) {
            System.out.println(e.getMessage());
        }
        try {
            login("admin","123");
        } catch (UserNotExistException e) {
            System.out.println(e.getMessage());
        }

    }

    public static void register(String username, String password) throws UserExistException {
        if ("admin".equals(username) || "jack".equals(username)) {
            throw new UserExistException("该用户已经被注册");
        }
        System.out.println("注册成功");
    }

    public static void login(String username, String password) throws UserNotExistException {
        if ("admin".equals(username) && "123".equals(password)) {
            System.out.println("登录成功");
            return;
        }
        throw new UserNotExistException("用户名或者密码错误");
    }

}
